<template>
    <div class="detial">
        <div class="detial-header">
            <van-nav-bar title="产品详情" left-text="返回" left-arrow @click-left="$router.back()" fixed />
        </div>
        <div class="detial-banner">
            <van-swipe :loop="false" :width="375" :height="345" :autoplay="3000">
                <van-swipe-item v-for="item in gallery " :key="item.id">
                    <img :src="item.img_url" alt="">
                </van-swipe-item>
            </van-swipe>
        </div>
        <div class="detial-commit">
            <p class="detial-commit-item">30天无忧退货</p>
            <p class="detial-commit-item">48小时快速退款</p>
            <p class="detial-commit-item">满88元免邮费</p>
        </div>
        <div class="detial-info">
            <div class="detial-info-name">{{ infoList.name }}</div>
            <div class="detial-info-desc">{{ infoList.goods_brief }}</div>
            <div class="detial-info-price">￥{{ infoList.retail_price }}</div>
            <div class="detial-info-bottom">
                <div class="bottom-tltle">请选择规格数量</div>
                <div class="bottom-icon"><img
                        src=""
                        alt=""></div>
            </div>
        </div>
        <div class="detial-params">
            <div class="detial-params-title">商品参数</div>
            <div class="detial-params-desc">
                <div class="desc-item" v-for="(item, index) in attributeList" :key="index">
                    <div class="desc-item-name">{{ item.name }}</div>
                    <div class="desc-item-content">
                        <p class="content-title">{{ item.value }}</p>
                    </div>
                </div>
            </div>
        </div>
        <div v-html="desc" class="detial-desc"></div>
        <div class="detial-issue">
            <div class="detial-issue-title">常见问题</div>
            <div class="detial-issue-question" v-for="item in isueList" :key="item.id">
                <h5 class="question-top">{{ item.question }}</h5>
                <p class="question-bottom">{{ item.answer }}</p>
            </div>
        </div>
        <div class="detial-goods">
            <div class="goods-title">大家都在看</div>
            <div class="goods-content">
                <div class="goods-item" v-for="item in productList" :key="item.id"
                    @click="$router.push({ name: 'detial', params: { id: item.id } })">
                    <img :src="item.list_pic_url" alt="" class="goods-item-img">
                    <div class="goods-item-name">{{ item.name }}</div>
                    <div class="goods-item-price">￥{{ item.retail_price }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getgoodsDetailsApi } from '@/api/detail'
import { useRoute } from 'vue-router';
import detialitem from './detialitem.vue';
const route = useRoute()
// 这是详情页轮播图数据
const gallery = ref<detialNs.IgalleryData[]>([])
// 这里是商品info数据
const infoList = ref<detialNs.IinfoData>({ id: 0, name: '', goods_brief: '', retail_price: 0, goods_desc: '',primary_pic_url:''})
const desc = ref<string>('')
// 这里是商品参数的数据
const attributeList = ref<detialNs.IattributeData[]>([])
// 这里是常见问题的数据
const isueList = ref<detialNs.IissueData[]>([])
// 这里是详情页的商品数据
const productList = ref<detialNs.IproductListData[]>([])
const getdetailHandler = async () => {
    let res = await getgoodsDetailsApi(Number((route.params.id)))
    console.log(res);
    gallery.value = res.gallery
    infoList.value = res.info
    attributeList.value = res.attribute
    desc.value = infoList.value.goods_desc.replace(/img/g, 'img style="width:100%;display:block;"')
    isueList.value = res.issue
    productList.value = res.productList
}
onMounted(() => {
    getdetailHandler()
})
</script>

<style scoped lang="scss">
.detial {
    .detial-header {
        height: 45px;
    }

    .detial-banner {
        width: 100%;
        height: 3.45rem;

        .van-swipe {
            .van-swipe__track {
                .van-swipe-item {
                    color: #fff;
                    font-size: 20px;
                    line-height: 150px;
                    text-align: center;
                    background: red;

                    img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
        }
    }

    .detial-commit {
        width: 100%;
        height: 0.5rem;
        background: #434343;
        margin-top: 15px;
        display: flex;
        justify-content: space-around;
        line-height: 0.5rem;
        color: #b3a80f;
        font-size: 12px;
    }

    .detial-info {
        width: 3.20rem;
        height: 1.62rem;
        background: #fff;
        margin: 10px auto 0;
        padding: 0 17.5px;
        overflow: hidden;

        .detial-info-name {
            font-size: 19px;
            color: #333333;
            margin-top: 17px;
        }

        .detial-info-desc {
            font-size: 13px;
            color: #999999;
            margin-top: 3.5px;
        }

        .detial-info-price {
            font-size: 17px;
            color: #9e4242;
            margin-top: 6px;
        }

        .detial-info-bottom {
            width: 100%;
            height: 0.42rem;
            border-top: 1px solid rgb(234, 234, 234);
            margin-top: 26px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .bottom-icon img {
                width: 15px;
                height: 15px;
                display: block;
            }
        }
    }

    .detial-params {
        display: flex;
        flex-direction: column;
        background: #fff;
        width: 3.56rem;
        margin: 10px auto;
        overflow: hidden;
        align-items: center;

        .detial-params-title {
            text-align: center;
            font-size: 19px;
            color: #333333;
            margin: 20px 0 0 0;
        }

        .detial-params-desc {
            width: 3.21rem;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            margin-bottom: 26px;

            .desc-item {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-top: 20px;

                .desc-item-name {
                    font-size: 13px;
                    color: #666666;
                    width: 0.52rem;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                .desc-item-content {
                    width: 2.54rem;
                    height: 0.32rem;
                    background: #F8F8F8;
                    border: 1px solid rgb(223, 223, 223);

                    .content-title {
                        text-align: center;
                        line-height: 0.32rem;
                        font-size: 13px;
                        color: #333;
                        white-space: nowrap;
                        width: 100%;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                }
            }

        }
    }

    .detial-desc {
        width: 3.56rem;
        display: flex;
        flex-direction: column;
        margin: 0 auto;

        img {
            width: 100%;
        }
    }

    .detial-issue {
        width: 3.37rem;
        height: 4.45rem;
        padding: 0 19px;
        background: #ffffff;
        display: flex;
        flex-direction: column;
        overflow: hidden;

        .detial-issue-title {
            font-size: 19px;
            margin-top: 20px;
            color: #333;
            text-align: center;
        }

        .detial-issue-question {
            width: 3.18rem;
            height: 0.72rem;
            padding: 20px 0 0 19px;

            .question-top {
                font-size: 15px;
                color: #333;
                font-weight: normal;
            }

            .question-bottom {
                width: 100%;
                font-size: 13px;
                color: #666;
                white-space: wrap;
                overflow: hidden;
                text-overflow: ellipsis;
                margin-top: 8px;
            }
        }
    }

    .detial-goods {
        width: 3.55rem;
        padding: 10px;
        display: flex;
        flex-direction: column;

        .goods-title {
            font-size: 19px;
            color: #333;
            text-align: center;
            margin-top: 20px;
            margin-bottom: 10px;
        }

        .goods-content {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;

            .goods-item {
                width: 1.75rem;
                height: 2.30rem;
                // background: green;
                margin-top: 10px;
                .goods-item-img {
                    width: 1.75rem;
                    height: 1.75rem;
                    background: #fff;
                }

                .goods-item-name {
                    font-size: 13px;
                    color: #333333;
                    margin-top: 8.5px;
                    white-space: nowrap;
                    width: 1.54rem;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                .goods-item-price {
                    color: #9e4242;
                    font-size: 13px;
                    margin-top: 3px;
                }
            }
        }
    }
}</style>